/* 无源汇上下界可行流问题
* 1.问题描述
    假设有一个流网络G，存在任意一个可行流f，不存在源点和汇点，我们需要将它转化成一个新的流网络G′，存在任意一个新的可行流f′，G′中存在源点和汇点，且只有上界没有下界
    对于流网络 G的可行流f中的某一条边 (u,v)，容量上界记为 Cu(u,v)，容量下界记为 Cl(u,v)，当前流量记为 f(u,v)。当前满足 Cl(u,v)≤f(u,v)≤Cu(u,v)
    把原等式的每一项都减去Cl(u,v)，即0≤f(u,v)-Cl(u,v)≤Cu(u,v)-Cl(u,v)

*/
#define DEBUG
#pragma GCC optimize("O1,O2,O3,Ofast")
#pragma GCC optimize("no-stack-protector,unroll-loops,fast-math,inline")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,ssse3")

#include <iostream>
#include <cstring>
using namespace std;
// #define int long long
const int N = 210, M = (10200+N)*2, INF = 0x3f3f3f3f;

int n, m, S, T;
int h[N], e[M], ne[M], f[M], l[M], idx; //f表示容量 l容量下界
int q[N], d[N], cur[N], A[N]; 
// d[i]: 分层图每个点的深度
// cur[i]：弧优化
// //A[i] 表示点i所有入边的容量下界之和 - 点i所有出边的容量下界之和

void AddEdge(int a, int b, int c, int d)
{
    e[idx] = b, f[idx] = d-c, l[idx] = c, ne[idx] = h[a], h[a] = idx++;
    e[idx] = a, f[idx] = 0, ne[idx] = h[b], h[b] = idx++;

}

bool bfs()
{
    int hh = 0, tt = -1;
    memset(d, -1, sizeof d);
    q[++tt] = S, d[S] = 0, cur[S] = h[S];

    while(hh <= tt)
    {
        int u = q[hh++];
        for(int i = h[u]; ~i; i = ne[i])
        {
            int v = e[i];
            if(d[v] == -1 && f[i])
            {
                d[v] = d[u]+1;
                cur[v] = h[v];
                if(v == T) return true;
                q[++tt] = v;
            }
        }
    }
    return false;
}

int find(int u, int limit)
{
    if(u == T) return limit;
    int flow = 0;
    for(int i = cur[u]; ~i && flow < limit; cur[u] = i, i = ne[i])
    {
        int v = e[i];
        if(d[v] == d[u] + 1 && f[i])
        {
            int t = find(v, min(f[i], limit-flow));
            if(!t) d[v] = -1;
            f[i] -= t, f[i^1] += t, flow += t;
        }
    }
    return flow;


}

int Dinic()
{
    int r = 0, flow;
    while(bfs())
        while(flow = find(S, INF)) r += flow;
    return r;
}

signed main()
{
    #ifdef DEBUG
        freopen("./in.txt", "r", stdin);
    #else
        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #endif

    cin >> n >> m;
    S = 0, T = n+1;
    memset(h, -1, sizeof h);
    for(int i = 0; i < m; i++)
    {
        int a, b, c, d; cin >> a >> b >> c >> d;
        AddEdge(a, b, c, d);
        A[a] -= c; A[b] += c;//点a出去了c的容量下界，点b进来了c的容量下界
    }

    int tot = 0;
    for(int i = 1; i <= n; i++)
        if(A[i] > 0) AddEdge(S, i, 0, A[i]), tot += A[i];
        else if(A[i] < 0) AddEdge(i, T, 0, -A[i]);
    if(Dinic() != tot) puts("NO");
    else{
        puts("YES");
        for(int i = 0; i < m*2; i+=2)
            printf("%d\n", f[i^1]+l[i]);//原图边的流量是残量网络反向边的容量，再加上容量下界
    }
}